<?php
declare (strict_types = 1);

namespace app\admin\controller\gm;

use think\facade\Request;
use app\common\service\GmSendgoodspls as S;
use app\common\model\GmSendgoodspls as M;
use app\common\model\AdminAdmin as UM;

class Sendgoodspls extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck','AdminPermission'];

    // 列表
    public function index(){
        if (Request::isAjax()) {
            return $this->getJson(M::getList());
        }
        return $this->fetch();
    }

    // 添加
    public function add(){
        if (Request::isAjax()) {
            return $this->getJson(S::goAdd(Request::post()));
        }
        return $this->fetch('add', ['ServerLs' => UM::getServerLsSelect(),'Goodsls' => UM::getGoodsSelect()]);
    }

    // 查询用户名
    public function queryuname(){
        $data = UM::getqueryuname(Request::post('actorname'), Request::post('serverid'));
        $response = [
            'msg' => '操作成功',
            'code' => 200,
            'data' => $data,
        ];
        return json($response);
    }

    // 编辑
    public function edit($id){
        if (Request::isAjax()) {
            // return $this->getJson(S::goEdit(Request::post(),$id));
            if (!empty(Request::post('actorname'))) {
                $data = UM::getqueryuname(Request::post('actorname'), Request::post('serverid'));
                $response = [
                    'msg' => '操作成功',
                    'code' => 200,
                    'data' => $data,
                ];
                return json($response);
            }else{
                return $this->getJson(S::goEdit(Request::post(),$id));
            }
        }
        return $this->fetch('',['model' => M::find($id),'ServerLs' => UM::getServerLsSelect(),'Goodsls' => UM::getGoodsSelect()]);
    }

    // 状态
    public function status($id){
        return $this->getJson(S::goStatus(Request::post('status'),$id));
        }

    // 删除
    public function remove($id){
        return $this->getJson(S::goRemove($id));
        }

    // 批量删除
    public function batchRemove(){
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
        }

    // 回收站
    public function recycle(){
        if (Request::isAjax()) {
            return $this->getJson(S::goRecycle());
        }
        return $this->fetch();
    }

}
